package com.itheima.sevrice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itheima.bean.SetmealDish;
import com.itheima.dao.SetmealDishDao;
import com.itheima.sevrice.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SetmealDishServiceImpl  implements SetmealDishService {

    @Autowired(required = false)
    private SetmealDishDao setmealDishDao;

    /**
     * 添加套餐——菜品
     *
     * @param setmealDish
     * @return
     */
    @Override
    public int add(SetmealDish setmealDish) {
        return  setmealDishDao.insert(setmealDish);
    }

    /**
     * 根据套餐id  删除 套餐菜品
     *
     * @param setmealIds
     * @return
     */
    @Override
    public int delete(List<Long> setmealIds) {

        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.in(SetmealDish::getSetmealId,setmealIds);
        return setmealDishDao.delete(lqw);
    }

    /**
     * 根据套餐的ID 查询所有的套餐菜品
     *
     * @param id
     * @return
     */
    @Override
    public List<SetmealDish> findById(Long id) {
        LambdaQueryWrapper<SetmealDish> lqw = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId,id);
        return setmealDishDao.selectList(lqw);
    }

    /**
     * 根据套餐id  删除 套餐菜品
     *
     * @param setmealId
     * @return
     */
    @Override
    public int deleteById(Long setmealId) {
        LambdaUpdateWrapper<SetmealDish> lqw = new LambdaUpdateWrapper<>();
        lqw.eq(SetmealDish::getSetmealId,setmealId);
        return setmealDishDao.delete(lqw);
    }


}
